#include <bits/stdc++.h>
using namespace std;
const int _ = 2e5 + 10;
const int __ = 4e5 + 10;
int n, m, q, u[_], v[_], fa[_], rnk[_], e, hd[_], nx[__], to[__];
bool vis[_], tmp, rig[_];
inline void add(int u, int v) {
    e++;
    nx[e] = hd[u];
    to[e] = v;
    hd[u] = e;
}
int tp, stk[_];
void dfs(int x, int f) {
    stk[++tp] = x;
    vis[x] = true;
    for (int i = hd[x]; i; i = nx[i]) {
        if (i != f) {
            int y = to[i];
            if (!vis[y]) {
                dfs(y, ((i-1)^1)+1);
            } else if (!tmp) {
                tmp = true;
                for (int j = tp;;j--) {
                    rig[stk[j]] = true;
                    if (stk[j] == y) break;
                }
            }
        }
    }
    tp--;
}
int find(int x) {
    if (x == fa[x]) return x;
    return fa[x] = find(fa[x]);
}
inline void join(int u, int v) {
    u = find(u);
    v = find(v);
    if (u != v) {
        if (rnk[u] < rnk[v]) {
            swap(u, v);
        } else if (rnk[u] == rnk[v]) {
            rnk[u]++;
        }
        fa[v] = u;
    }
}
bool stat[_];
int main() {
    freopen("graph.in", "r", stdin);
    freopen("graph.out", "w", stdout);
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> m;
    for (int i = 1; i <= m; i++) {
        cin >> u[i] >> v[i];
    }
    cin >> q;
    if (m == n) {
        for (int i = 1; i <= m; i++) {
            add(u[i], v[i]);
            add(v[i], u[i]);
        }
        dfs(1, 0);
        while (q--) {
            int k;
            cin >> k;
            if (k == 1) {
                int e;
                cin >> e;
                if (rig[u[e]] && rig[v[e]]) {
                    cout << "YES";
                } else {
                    cout << "NO";
                }
            } else {
                while (k--) {
                    int e;
                    cin >> e;
                }
                cout << "NO";
            }
            if (q) {
                cout << '\n';
            }
        }
        cout << endl;
    } else {
        while (q--) {
            for (int i = 1; i <= m; i++) {
                stat[i] = true;
            }
            int k;
            cin >> k;
            while (k--) {
                int e;
                cin >> e;
                stat[e] = false;
            }
            for (int i = 1; i <= n; i++) {
                fa[i] = i;
                rnk[i] = 0;
            }
            for (int i = 1; i <= m; i++) {
                if (stat[i]) {
                    join(u[i], v[i]);
                }
            }
            int cnt = 0;
            for (int i = 1; i <= n; i++) {
                if (fa[i] == i) {
                    cnt++;
                }
            }
            if (cnt == 1) {
                cout << "YES";
            } else {
                cout << "NO";
            }
            if (q) {
                cout << '\n';
            }
        }
        cout << endl;
    }
    return 0;
}